Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Feb 7, 2025

@llvm/pr-subscribers-objectyaml

Author: Kazu Hirata (kazutakahirata)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/126187.diff

1 Files Affected:

  • (modified) llvm/lib/ObjectYAML/DWARFEmitter.cpp (+4-7)
diff --git a/llvm/lib/ObjectYAML/DWARFEmitter.cpp b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
index 421dfe7dfa30efb..ec5e08082b0ca59 100644
--- a/llvm/lib/ObjectYAML/DWARFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DWARFEmitter.cpp
@@ -96,12 +96,11 @@ Error DWARFYAML::emitDebugStr(raw_ostream &OS, const DWARFYAML::Data &DI) {
 StringRef DWARFYAML::Data::getAbbrevTableContentByIndex(uint64_t Index) const {
   assert(Index < DebugAbbrev.size() &&
          "Index should be less than the size of DebugAbbrev array");
-  auto It = AbbrevTableContents.find(Index);
-  if (It != AbbrevTableContents.cend())
+  auto [It, Inserted] = AbbrevTableContents.try_emplace(Index);
+  if (!Inserted)
     return It->second;
 
-  std::string AbbrevTableBuffer;
-  raw_string_ostream OS(AbbrevTableBuffer);
+  raw_string_ostream OS(It->second);
 
   uint64_t AbbrevCode = 0;
   for (const DWARFYAML::Abbrev &AbbrevDecl : DebugAbbrev[Index].Table) {
@@ -123,9 +122,7 @@ StringRef DWARFYAML::Data::getAbbrevTableContentByIndex(uint64_t Index) const {
   // consisting of a 0 byte for the abbreviation code.
   OS.write_zeros(1);
 
-  AbbrevTableContents.insert({Index, AbbrevTableBuffer});
-
-  return AbbrevTableContents[Index];
+  return It->second;
 }
 
 Error DWARFYAML::emitDebugAbbrev(raw_ostream &OS, const DWARFYAML::Data &DI) {

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@kazutakahirata kazutakahirata merged commit dbb20fc into llvm:main Feb 7, 2025
10 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_repeated_hash_lookups_llvm_ObjectYAML branch February 7, 2025 15:59
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants